package com.kyomonn.talkischeap.CodingResources;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kyomonn.talkischeap.R;

public class BookTabButtonAdapter extends BaseAdapter {
    private final Context context;
    private final int resource;
    private final String[] titles;
    private final int[] imageIDs;

    public BookTabButtonAdapter(Context context, int resource, String[] titles, int[] imageIDs) {
        this.context = context;
        this.resource = resource;
        this.titles = titles;
        this.imageIDs = imageIDs;
    }

    @Override
    public int getCount() {
        return titles.length;
    }

    @Override
    public Object getItem(int i) {
        return titles[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        return null;
    }

    static class ViewHolder {
        private final View itemBook;

        private final ImageView imageView;
        private final TextView textView;

        public ViewHolder(View itemBook) {
            this.itemBook = itemBook;
            this.imageView = itemBook.findViewById(R.id.iv_book_cover);
            this.textView = itemBook.findViewById(R.id.tv_book_title);
        }

        public void bind(int imageID, String title, View.OnClickListener callback) {
            imageView.setImageResource(imageID);
            textView.setText(title);
            itemBook.setOnClickListener(callback);
        }
    }
}
